package com.tool.toollibrary.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Michael on 2017/8/7.
 */

public abstract  class BaseFragment extends Fragment {
    //获取全局上下文
    public Context mContext;
    public LayoutInflater mInflater;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.mContext=getActivity();
        this.mInflater=LayoutInflater.from(mContext);

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        return initView();//返回的是子类的View，，调用抽象方法。由子类自己去实现布局

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData(); //由子类初始化数据
    }

    public  void initData() {

    }
    //定义抽象方法，必须由子类实现，
    public abstract  View initView();


}
